package com.we.flink.userlabelplatform.table;

public class TableUserLoan {
    public static final String KFKTABLE = "fdm.hhl01_user_loan";
    //    public static final String KFKTABLE = "fdm.hhl01_user_loan_risk";
    public static final String QUERYSQL =
            "select uid, loan_id, "
                    + "cast(if(status is null, 0, status) as tinyint) as status,"
                    + "cast(if(repay_status is null, 0, repay_status) as tinyint) as repay_status, "
                    + "if(emit_time is null, 2147483647, emit_time) as emit_time, "
                    + "if(borrow_time is null, -2147483648, borrow_time) as borrow_time, "
                    + "if(expire_time is null, -2147483648, expire_time) as expire_time "
                    + "from "
                    + KFKTABLE
                    + " where deleted_at is null";

    public long uid;
    public int loan_id;
    public int status;
    public int repay_status;
    public int emit_time;
    public int borrow_time;
    public int expire_time;

    public TableUserLoan() {}

    public TableUserLoan(
            long uid,
            int loan_id,
            int status,
            int repay_status,
            int emit_time,
            int borrow_time,
            int expire_time) {
        this.uid = uid;
        this.loan_id = loan_id;
        this.status = status;
        this.repay_status = repay_status;
        this.emit_time = emit_time;
        this.borrow_time = borrow_time;
        this.expire_time = expire_time;
    }

    //    public static TableUserLoan of(long uid, int loanId, int status, int repayStatus, int
    // emitTime, int borrowTime) {
    //        return new TableUserLoan(uid, loanId, status, repayStatus, emitTime, borrowTime);
    //    }

    //    public static TableUserLoan empty() {
    //        byte status = 0;
    //        byte repayStatus = 0;
    //        return new TableUserLoan(0L, 0, status, repayStatus, Integer.MAX_VALUE,
    // Integer.MIN_VALUE);
    //    }

    public long getUid() {
        return uid;
    }

    public int getStatus() {
        return status;
    }

    public int getLoan_id() {
        return loan_id;
    }

    public int getRepay_status() {
        return repay_status;
    }

    public int getEmit_time() {
        return emit_time;
    }

    public int getBorrow_time() {
        return borrow_time;
    }

    public int getExpire_time() {
        return expire_time;
    }

    @Override
    public String toString() {
        return "TableUserLoan{"
                + "uid="
                + uid
                + ", loan_id="
                + loan_id
                + ", status="
                + status
                + ", repay_status="
                + repay_status
                + ", emit_time="
                + emit_time
                + ", borrow_time="
                + borrow_time
                + '}';
    }

    /** just for nc -lk test */
    /*private static class TableUserLoanMapFunction extends RichMapFunction<String, Tuple2<Boolean, TableUserLoan>> {
    private static final int CLMLEN = 41;

    @Override
    public Tuple2<Boolean, TableUserLoan> map(String value) throws Exception{
        long uid;
        int loanId;
        byte status;
        byte repayStatus;
        int emitTime;
        int borrowTime;
        boolean binlogFlag;
        int expireTime;

        try {
            String[] splits = value.split("##");
            if(splits.length != CLMLEN) {
                System.out.println("TableUserLoanMapFunction splits length eror,input: " + value);
                return new Tuple2<>(true, TableUserLoan.empty());
            }

            */
    /** 注意mysql 对应表中某些字段允许null值 code针对kafka bin log解析遇到空值就会映射成下面的默认值 全0 */
    /*
                    binlogFlag = (splits[40].length() > 0) ? Boolean.parseBoolean(splits[40]) : true;
                    loanId = (splits[1].length() > 0) ? Integer.parseInt(splits[1]) : 0;
                    uid = (splits[2].length() > 0) ? Long.parseLong(splits[2]) : 0L;
                    borrowTime = (splits[11].length() > 0) ? Integer.parseInt(splits[11]) : Integer.MIN_VALUE;
                    emitTime = (splits[29].length() > 0) ? Integer.parseInt(splits[29]) : Integer.MAX_VALUE;
                    repayStatus = (splits[32].length() > 0) ? Byte.parseByte(splits[32]) : 0;
                    status = (splits[33].length() > 0) ? Byte.parseByte(splits[33]) : 0;
                    expireTime =



    //            System.out.println("TableUserLoanMapFunction uid:" + uid);
    //            System.out.println("TableUserLoanMapFunction loanId:" + loanId);
    //            System.out.println("TableUserLoanMapFunction status:" + status);
    //            System.out.println("TableUserLoanMapFunction repayStatus:" + repayStatus);
    //            System.out.println("TableUserLoanMapFunction emitTime:" + emitTime);
    //            System.out.println("TableUserLoanMapFunction borrowTime:" + borrowTime);
    //            System.out.println("###binlogFlag###: " + binlogFlag);
                    return new Tuple2<>(binlogFlag, TableUserLoan.of(uid, loanId, status, repayStatus, emitTime, borrowTime));
                } catch (Exception E) {
                    System.out.println("TableUserLoanMapFunction exception input: "+value);
                    System.out.println(E.getMessage());
                    E.printStackTrace();
                }
                return new Tuple2<>(true, TableUserLoan.empty());
            }

        }*/

}
